﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Text1
{
    public interface IHandler
    {
        void Register(Dictionary<Protocal, Action<SockedClient,ByteBuffer>> handlers);
    }
    class HandlerCenter
    {
        //所有协议对应的处理函数
        Dictionary<Protocal, Action<SockedClient,ByteBuffer>> handlers = new Dictionary<Protocal, Action<SockedClient ,ByteBuffer>>();

        AccountHander accountHandler=new AccountHander();
        BattleHandler battleHandler=new BattleHandler();
        public HandlerCenter()
        {
            accountHandler.Register(handlers);
            battleHandler.Register(handlers);
        }
        public void RecieveMessage(SockedClient client,ByteBuffer buffer)
        {
            Protocal type = (Protocal)buffer.ReadByte();

            handlers[type](client,buffer);
        }
    }
}
